package com.forum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.forum.model.entity.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TagMapper extends BaseMapper<Tag> {
    @Select("SELECT * FROM tag ORDER BY use_count DESC")
    List<Tag> selectAll();

    @Select("SELECT * FROM tag WHERE name = #{name}")
    Tag selectByName(String name);

    @Insert("INSERT INTO tag (name, use_count, created_at) VALUES (#{name}, #{useCount}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Tag tag);

    @Update("UPDATE tag SET use_count = use_count + 1 WHERE id = #{id}")
    int incrementUseCount(Long id);
} 